package com.admin.business.recallUser;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 物业公司用户表罢免委员
 * @create: 2023-10-28 09:27:23
 **/
@Service("recallUserService")
@Slf4j
public class RecallUserService{

    @Resource
    RecallUserDao recallUserDao;

    /**
     * 添加物业公司用户表罢免委员,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id_zyw:用户id
     *                   - recall_id:解聘记录id
     *                   - user_floor_number:楼号
     *                   - user_state:用户状态：0业主 1业委会成员 2工作组成员
     *                   - user_reconsider_state:复议状态：0已复议，1未复议
     *                   - user_age:年龄
     *                   - user_gender:性别
     *                   - user_nation:民族
     *                   - user_political_outlook:政治面貌
     *                   - user_duties:单位或职务
     *                   - user_declaration:个性宣言
     *                   - user_coronal_photo:冠冕照
     *                   - user_payment_certificate:上传缴费证明
     *                   - user_auxiliary_materials:其他辅助材料
     *                   - committee_application:是否报名委员：0否 1是
     *                   - committee_qualification:是否是委员： 1是 ，0否
     *                   - committee_content:内容
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return addRecallUser(CDO cdoRequest) {
        recallUserDao.addRecallUser(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新物业公司用户表罢免委员数据
     *
     * @param cdoRequest - id:
     *                   - user_id_zyw:用户id
     *                   - recall_id:解聘记录id
     *                   - user_floor_number:楼号
     *                   - user_state:用户状态：0业主 1业委会成员 2工作组成员
     *                   - user_reconsider_state:复议状态：0已复议，1未复议
     *                   - user_age:年龄
     *                   - user_gender:性别
     *                   - user_nation:民族
     *                   - user_political_outlook:政治面貌
     *                   - user_duties:单位或职务
     *                   - user_declaration:个性宣言
     *                   - user_coronal_photo:冠冕照
     *                   - user_payment_certificate:上传缴费证明
     *                   - user_auxiliary_materials:其他辅助材料
     *                   - committee_application:是否报名委员：0否 1是
     *                   - committee_qualification:是否是委员： 1是 ，0否
     *                   - committee_content:内容
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return updateRecallUserById(CDO cdoRequest) {
        recallUserDao.updateRecallUserById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除物业公司用户表罢免委员数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteRecallUserById(CDO cdoRequest){
        int count = recallUserDao.deleteRecallUserById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除物业公司用户表罢免委员数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return deleteRecallUser(CDO cdoRequest) {
        int count = recallUserDao.deleteRecallUser(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取物业公司用户表罢免委员数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getRecallUserById(CDO cdoRequest) {
        CDO cdoMapperResult = recallUserDao.getRecallUserById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取物业公司用户表罢免委员数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getRecallUserListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = recallUserDao.getRecallUserListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = recallUserDao.getRecallUserCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取物业公司用户表罢免委员数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-28 09:27:23
     */
    @OpenApi
    public Return getRecallUserListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = recallUserDao.getRecallUserListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = recallUserDao.getRecallUserCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
